package com.yxc.emqxdemo.configuration;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * emqx消费者
 *
 * @author: YXC
 * @time: 2022/10/17 11:23
 **/
public abstract class EmqxConsumerParent {

    List<String> msgList = Collections.synchronizedList(new ArrayList<>());

    int size = 1000;

    public void receive(String msg) {
        msgList.add(msg);
        synchronized (this) {
            if (msgList.size() >= size) {
                this.receiveMessages(msgList);
                msgList.clear();
            }
        }
    }

    public abstract void receiveMessage(String msg);

    public abstract void receiveMessages(List<String> msgList);

}
